package com.campus.delivery.controller;

import cn.hutool.core.bean.BeanUtil;
import com.campus.common.bean.common.Resp;
import com.campus.delivery.bean.DeliveryUserUpdateBean;
import com.campus.delivery.entity.DeliveryUser;
import com.campus.delivery.service.DeliveryUserService;
import com.campus.delivery.vo.UserInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 配送员用户表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-05-12
 */
@RestController
@RequestMapping("/deliveryUser")
public class DeliveryUserController {

    @Autowired
    private DeliveryUserService deliveryUserService;

    /**
     * 更新配送员昵称和头像
     */
    @ApiOperation("更新配送员昵称和头像")
    @PostMapping("/updateProfile")
    public Resp<UserInfoVo> updateProfile(@Validated @RequestBody DeliveryUserUpdateBean bean) {
        //昵称和头像不能同时为空
        if (bean.getNickname() == null && bean.getAvatar() == null) {
            return Resp.error("昵称和头像不能同时为空");
        }
        DeliveryUser user = deliveryUserService.updateNicknameAndAvatar(bean.getId(), bean.getNickname(), bean.getAvatar());
        UserInfoVo vo = new UserInfoVo();
        BeanUtil.copyProperties(user, vo);
        return Resp.success(vo);
    }
}